package com.dmgis.hndz.api;




import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dmgis.hndz.common.config.DbConfig;
import com.dmgis.hndz.common.utils.StringUtil;
import com.dmgis.hndz.common.UrlHttpRequest;
import com.dmgis.hndz.pojo.City;
import org.springframework.stereotype.Repository;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class ZhcxApi {
    /***
     * 公共方法
     * @param paramtype
     * @param o
     * @param <T>
     * @return
     */
    public <T> List<T> GetZhcxData(String paramtype, Object o) {
        List<T> zxqfks = new ArrayList<>();
        Map<String, Object> parameters = new HashMap<>();
        UrlHttpRequest request = new UrlHttpRequest();
        Field[] fields = o.getClass().getDeclaredFields();
        for (Field field : fields) {
            parameters.put(field.getName(), request.getFieldValueByName(field.getName(), o));
        }
        String url = DbConfig.Uri + "ZHCXNew/" + paramtype + "?";
        String result = request.httpPost(url, parameters);
        if (!StringUtil.IsNullOrEmpty(result)) {
            JSONObject object = JSONObject.parseObject(result);
            JSONArray data = object.getJSONArray("data");
            if (data != null)
                zxqfks = (List<T>) JSONObject.parse(data.toJSONString());
        }
        return zxqfks;
    }

    public <T> List<T> selectSbdNumBySy(City city) {
        return GetZhcxData("selectSbdNumBySyNew", city);
    }

    /**
     * @Description:综合查询-行政单元-调查点查询
     */
    public <T> List<T> queryZhcxXzdyByDcd(City o) {
        return GetZhcxData("queryZhcxXzdyByDcdNew", o);
    }

    /**
     * @Description:综合查询-灾害点灾情
     */
    public <T> List<T> queryZhcxZq(City o) {
        return GetZhcxData("queryZhcxZqNew", o);
    }

    /**
     * @Description:综合查询-灾害点灾情
     */
    public <T> List<T> queryZhcxXq(City o) {
        return GetZhcxData("queryZhcxXqNew", o);
    }

    /**
     * @Description:速报点信息
     */
    public <T> List<T> selectSbdInfo(City city) {
        return GetZhcxData("selectSbdInfoNew", city);
    }

    public <T> List<T> selectCancelZhd(City city) {
        return GetZhcxData("selectCancelZhdNew", city);
    }

    /**
     * @Description:综合查询-灾害点详情
     */
    public <T> List<T> queryZhcxZhd(City o) {
        return GetZhcxData("queryZhcxZhdNew", o);
    }
}